#ifndef __BASE_TYPES_COMMON_H__
#define __BASE_TYPES_COMMON_H__
#include <cfgcomm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>

#if DEVICE_PLATFORM_CONFIGURE == DEVICE_PLATFORM_C51_MCU
#define DEV_C51_XDATA_FLAG xdata
#if DEV_PLAT_51_CHIP_TYPE == DEV_PLAT_51_STC32
// STC32 have not code flag.
#define DEV_C51_CODE_FLAG
#else
#define DEV_C51_CODE_FLAG code
#endif
typedef char int8_t;
typedef unsigned char uint8_t;
typedef int int16_t;
typedef unsigned int uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
// include 51 head
#if DEV_PLAT_51_CHIP_TYPE == DEV_PLAT_51_STC11
#include <STC11.h>
#elif DEV_PLAT_51_CHIP_TYPE == DEV_PLAT_51_STC8H
#include <STC8H.h>
#elif DEV_PLAT_51_CHIP_TYPE == DEV_PLAT_51_STC32
#include <stc32g.h>
#endif
#else
#include <inttypes.h>
#define DEV_C51_XDATA_FLAG
#define DEV_C51_CODE_FLAG
#endif

#if DEVICE_PLATFORM_CONFIGURE == DEVICE_PLATFORM_LINUX
// for linux
#include <pthread.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#endif

// 通过成员地址找到结构体变量地址。
#define container_of(ptr, type, member) ((type *)((char *)(ptr) - (char *)(&((type *)0)->member)))
// 求数组长度
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
// 将整数、浮点数控制在一个范围。
#define LIMIT_VAL(a, min, max) ((a) > (max) ? (max) : ((a) < (min) ? (min) : (a)))
// 循环加
#define CYCLE_ADD(a, add, len) (((a) + (add)) % (len))
// 交换整形数据宏
#define SWAP_BASE_VAL(a, b) (a ^= b, b ^= a, a ^= b)

#endif
